package com.letian.web.controller.im;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.letian.common.annotation.Log;
import com.letian.common.core.controller.BaseController;
import com.letian.common.core.domain.AjaxResult;
import com.letian.common.enums.BusinessType;
import com.letian.im.domain.ImFriendsRequest;
import com.letian.im.service.IImFriendsRequestService;
import com.letian.common.utils.poi.ExcelUtil;
import com.letian.common.core.page.TableDataInfo;

/**
 * 好友请求Controller
 * 
 * @author bmz
 * @date 2023-08-13
 */
@RestController
@RequestMapping("/info/friendsRequest")
public class ImFriendsRequestController extends BaseController
{
    @Autowired
    private IImFriendsRequestService imFriendsRequestService;

    /**
     * 查询好友请求列表
     */
    @PreAuthorize("@ss.hasPermi('info:friendsRequest:list')")
    @GetMapping("/list")
    public TableDataInfo list(ImFriendsRequest imFriendsRequest)
    {
        startPage();
        List<ImFriendsRequest> list = imFriendsRequestService.selectImFriendsRequestList(imFriendsRequest);
        return getDataTable(list);
    }

    /**
     * 导出好友请求列表
     */
    @PreAuthorize("@ss.hasPermi('info:friendsRequest:export')")
    @Log(title = "好友请求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ImFriendsRequest imFriendsRequest)
    {
        List<ImFriendsRequest> list = imFriendsRequestService.selectImFriendsRequestList(imFriendsRequest);
        ExcelUtil<ImFriendsRequest> util = new ExcelUtil<ImFriendsRequest>(ImFriendsRequest.class);
        util.exportExcel(response, list, "好友请求数据");
    }

    /**
     * 获取好友请求详细信息
     */
    @PreAuthorize("@ss.hasPermi('info:friendsRequest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(imFriendsRequestService.selectImFriendsRequestById(id));
    }

    /**
     * 新增好友请求
     */
    @PreAuthorize("@ss.hasPermi('info:friendsRequest:add')")
    @Log(title = "好友请求", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ImFriendsRequest imFriendsRequest)
    {
        return toAjax(imFriendsRequestService.insertImFriendsRequest(imFriendsRequest));
    }

    /**
     * 修改好友请求
     */
    @PreAuthorize("@ss.hasPermi('info:friendsRequest:edit')")
    @Log(title = "好友请求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ImFriendsRequest imFriendsRequest)
    {
        return toAjax(imFriendsRequestService.updateImFriendsRequest(imFriendsRequest));
    }

    /**
     * 删除好友请求
     */
    @PreAuthorize("@ss.hasPermi('info:friendsRequest:remove')")
    @Log(title = "好友请求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(imFriendsRequestService.deleteImFriendsRequestByIds(ids));
    }
}
